import React from 'react';
import { Router, Route, browserHistory } from 'react-router';
import Account from '../../ui/Account.jsx';

// route components
import AppContainer from '../../ui/App.jsx';
import { Session } from 'meteor/session'


//添加一个路由判断，如果系统还没有session的情况下，需要用户进行登录
//add by jiangbuyun 2017-01-17
const authHit= (nextState, replace) => {
    var loginuser = Session.get("currentUser");
    if(! loginuser){
      replace({
                pathname: '/login',
                state: { nextPathname: nextState.location.pathname }
      });
    }
}

//modify by jiangbuyun 2017-01-17
export const renderRoutes = () => (
  <Router history={browserHistory}>
    <Route path='/login' component={Account} />
    
    <Route path="/" component={AppContainer} onEnter={authHit}>
        <Route path=":tab" component={AppContainer}/>
    </Route>
    <Route path="/:tab/:uid" component={AppContainer}>
    </Route>
  </Router>
);

//modify by jiangbuyun 2017-01-17
/*export const renderRoutes = () => (
  <Router history={browserHistory}>
    <Route path='/login' component={Account} />
    
    <Route path="/" component={AppContainer} >
        <Route path=":tab" component={AppContainer}/>
    </Route>
    <Route path="/:tab/:uid" component={AppContainer}>
    </Route>
  </Router>
);*/